package com.shwread.android.qysw.activity;

import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.shwread.android.qysw10000182.R;
import logic.constants.DefaultConsts;


public class GameWebActivity
        extends
        BaseBusinessActivity
        implements
        OnClickListener
{
	private HTML5WebView mWebView;
	private TextView     tvTitle = null;
	private Button       btnBack = null;
	private String       mTitle  = "";
	private String       mUrl    = "";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mWebView = new HTML5WebView(this);
		
		Bundle bundle = getIntent().getExtras();
		mTitle = bundle.getString(DefaultConsts.title_s);
		mUrl = bundle.getString(DefaultConsts.req_url_s);
		if (savedInstanceState != null)
		{
			mWebView.restoreState(savedInstanceState);
		}
		else
		{
			mWebView.loadUrl(mUrl);
		}
		
		setContentView(mWebView.getLayout());
		initView();
		setListener();
	}
	
	private void initView() {
		tvTitle = (TextView) findViewById(R.id.common_header_name);
		tvTitle.setText(mTitle);
		btnBack = (Button) findViewById(R.id.common_header_back);
		btnBack.setVisibility(View.VISIBLE);
	}
	
	private void setListener() {
		btnBack.setOnClickListener(this);
	}
	
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		mWebView.saveState(outState);
	}
	
	@Override
	public void onStop() {
		super.onStop();
		mWebView.stopLoading();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			if (mWebView.inCustomView())
			{
				mWebView.hideCustomView();
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public Handler getUIHandler() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
    public void onClick(View v) {
		switch (v.getId()) {
			case R.id.common_header_back:
				finish();
				break;
		}
    }
}
